package ai.people.netmon.warning.grpc.account;

import ai.people.core.grpc.lib.key.account.KeyAccount;
import ai.people.core.grpc.lib.warning.AccountAnalysisListGrpcRequest;
import ai.people.core.grpc.lib.warning.AccountAnalysisListGrpcResponse;
import ai.people.core.grpc.lib.warning.AccountInfoGrpcRequest;
import ai.people.core.grpc.lib.warning.WarningAccountServiceGrpc;
import ai.people.core.grpc.utils.ProtoJsonUtil;
import ai.people.core.grpc.utils.StreamObserverDelegate;
import ai.people.netmon.framework.domain.warning.vo.WarningAccountVO;
import ai.people.netmon.warning.service.WarningAccountService;
import com.alibaba.fastjson.JSON;
import com.google.protobuf.Message;
import io.grpc.stub.StreamObserver;
import lombok.RequiredArgsConstructor;
import net.devh.boot.grpc.server.service.GrpcService;

/**
 * @author yuanqinglong
 * @date 2022/8/5 11:40
 */
@GrpcService
@RequiredArgsConstructor
public class WarningAccountGrpcService extends WarningAccountServiceGrpc.WarningAccountServiceImplBase {


    private final WarningAccountService warningAccountServiceImpl;

    /**
     * 账户信息
     *
     * @param request          请求
     * @param responseObserver 响应观察者
     */
    @Override
    public void accountInfo(AccountInfoGrpcRequest request, StreamObserver<KeyAccount> responseObserver) {
        StreamObserverDelegate.build(responseObserver).execute(() -> {
            WarningAccountVO accountBaseInfo = warningAccountServiceImpl.getAccountBaseInfo(request.getId());
            Message message = ProtoJsonUtil.toProtoMessage(KeyAccount.newBuilder(), JSON.toJSONString(accountBaseInfo));
            return (KeyAccount)message;
        });
    }


    /**
     * 用户加入账号分析列表接口
     *
     * @param request          请求
     * @param responseObserver 响应观察者
     */
    @Override
    public void accountJoinAnalysisList(AccountAnalysisListGrpcRequest request, StreamObserver<AccountAnalysisListGrpcResponse> responseObserver) {
        //StreamObserverDelegate.build(responseObserver).execute(() -> {
        //    ListResponse<JoinAnalysisAccountVO> joinAnalysisAccountVOListResponse = warningAccountServiceImpl.listJoinAnalysisAccount(request.getUserId());
        //    Message message = ProtoJsonUtil.toProtoMessage(AccountAnalysisListGrpcResponse.newBuilder(), JSON.toJSONString(joinAnalysisAccountVOListResponse));
        //    return (AccountAnalysisListGrpcResponse)message;
        //});
    }
}
